/********************************************************************************
TITLE:                      	Using Virtual Functions
FILENAME:                   	time.cpp
PREPARED FOR:               	CS215 Section CS13-02
PROGRAMMER(S):              	Eric (Fox) Crowell, (Tim, add full name here)
DEVELOPMENT DATE:           	< 12/15/13 >
COMPILER USED:      			Microsoft Visual Studio Professional 2013
                                     - Version 12.0.21005.1 REL
TARGET PLATFORM:         	    Windows 8 x64
================================================================================
REVISION HISTORY

DATE         PROGRAMMER          DESCRIPTION OF CHANGES MADE
------------------------------------------------------------------------------
<12/15/13       Fox                 CPP File created.                        >
<12/15/13       Fox                 CPP File created.                        >
*******************************************************************************/

#include "time.h"

// Constructor [Fox]
Time::Time(int InHours, int InMinutes) {
	SetHours(InHours); // Use the SetHours member function. [Fox]
	SetMinutes(InMinutes); // Use the SetMinutes member function. [Fox]
	OverHours = 0;
}

// Sets both the hours and minutes. [Fox]
void Time::SetTime(int NewHours, int NewMinutes){
	SetHours(NewHours);
	SetMinutes(NewMinutes);
}

// Sets a new value for the "Hours" data member. [Fox]
void Time::SetHours(int NewHours){
	Hours = NewHours >= 0 ? NewHours : 0;
	//if (Hours > 99){ Hours = 99; } // Ensure the number of hours does not go above 99. [Fox]
}

// Sets a new value for the "Minutes" data member. [Fox]
// Resets minutes and resets hours. [Fox]
void Time::SetMinutes(int NewMinutes){
	Minutes = NewMinutes >= 0 ? NewMinutes % 60 : 0;
	OverHours = NewMinutes >= 0 ? NewMinutes / 60 : 0;
}

// Return the "Hours" data member. [Fox]
// Modified to a constant function. [Fox]
int Time::GetHours() const{
	return((Hours + OverHours) > 99 ? 99 : (Hours + OverHours));
}

// Return the "Minutes" data member. [Fox]
// Modified to a constant function. [Fox]
int Time::GetMinutes() const{
	return(Minutes);
}

// Friend of "Time" class. [Fox]
// Outputs out the Hours and Minutes data members to the stream (time format).
ostream & operator<<(ostream & Out, Time & RHS){
	ostringstream formattedStream; // Created a atring stream to hold the formatting.
	formattedStream << setfill('0') << setw(2) << RHS.Hours << ":" << setw(2) << RHS.Minutes; // Stream in the data.
	Out << formattedStream.str(); // Stream into "Out" ostream.
	return(Out); // Return the ostream.
}